package com.cloudlinkscm.base.authcenter.dao;

import com.cloudlinkscm.base.authcenter.mapper.TenantResourceMapper;
import com.cloudlinkscm.base.authcenter.model.TenantResource;
import com.cloudlinkscm.loms.framework.dao.GenericBizDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * @author : tac
 * @date : 31/07/2017
 */
@Repository
public class TenantResourceDao extends GenericBizDao<TenantResource, String> {

    @Autowired
    public TenantResourceDao(TenantResourceMapper mapper) {
        super(mapper);
    }

    public int deleteByPrimaryKeyRecursively(String id) {
        return deleteByPrimaryKey(id);
    }

    public List<TenantResource> selectByTenantId(String tenantId) {
    	TenantResource tenantResource = new TenantResource();
	    tenantResource.setTenantId(tenantId);
    	return select(tenantResource);
    }

	public TenantResource selectByTenantIdAndResourceKey(String tenantId, String resourceKey) {
		TenantResource tenantResource = new TenantResource();
		tenantResource.setTenantId(tenantId);
		tenantResource.setResourceKey(resourceKey);
		return selectOne(tenantResource);
	}

    public List<TenantResource> selectByPid(String pid) {
	    TenantResource tenantResource = new TenantResource();
	    tenantResource.setPid(pid);
	    return select(tenantResource);
    }

	public List<TenantResource> selectByIds(Collection<String> resourceIds) {
		Example example = new Example(TenantResource.class);
		example.createCriteria().andIn("id", resourceIds);
    	return selectByExample(example);
	}

	public int deleteByIds(Collection<String> ids) {
		Example example = new Example(TenantResource.class);
		example.createCriteria().andIn("id", ids);
    	return deleteByExample(example);
	}
}
